crate_types: &BTreeSet<String>,
kind: Kind)
-> CargoResult<()> {
+ let rustflags = try!(env_args(self.config,
+ &self.build_config,
+ kind,
+ "RUSTFLAGS"));
let mut process = util::process(self.config.rustc());
process.arg("-")
.arg("--crate-name").arg("_")
.arg("--print=file-names")
- .args(&try!(rustflags_args(self.config, &self.build_config, kind)))
+ .args(&rustflags)
.env_remove("RUST_LOG");
for crate_type in crate_types {
}
pub fn rustflags_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
- rustflags_args(self.config, &self.build_config, unit.kind)
+ env_args(self.config, &self.build_config, unit.kind, "RUSTFLAGS")
+ }
+
+ pub fn rustdocflags_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
+ env_args(self.config, &self.build_config, unit.kind, "RUSTDOCFLAGS")
}
pub fn show_warnings(&self, pkg: &PackageId) -> bool {
// Acquire extra flags to pass to the compiler from the
// RUSTFLAGS environment variable and similar config values
-fn rustflags_args(config: &Config,
- build_config: &BuildConfig,
- kind: Kind) -> CargoResult<Vec<String>> {
+fn env_args(config: &Config,
+ build_config: &BuildConfig,
+ kind: Kind,
+ name: &str) -> CargoResult<Vec<String>> {
// We *want* to apply RUSTFLAGS only to builds for the
// requested target architecture, and not to things like build
// scripts and plugins, which may be for an entirely different
}
// First try RUSTFLAGS from the environment
- if let Some(a) = env::var("RUSTFLAGS").ok() {
+ if let Some(a) = env::var(name).ok() {
let args = a.split(" ")
.map(str::trim)
.filter(|s| !s.is_empty())
}
// Then the build.rustflags value
- if let Some(args) = try!(config.get_list("build.rustflags")) {
+ let name = name.chars().flat_map(|c| c.to_lowercase()).collect::<String>();
+ let key = format!("build.{}", name);
+ if let Some(args) = try!(config.get_list(&key)) {
let args = args.val.into_iter().map(|a| a.0);
return Ok(args.collect());
}
};
let mut deps = deps;
deps.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b));
+ let extra_flags = if unit.profile.doc {
+ try!(cx.rustdocflags_args(unit))
+ } else {
+ try!(cx.rustflags_args(unit))
+ };
let fingerprint = Arc::new(Fingerprint {
rustc: util::hash_u64(&cx.config.rustc_info().verbose_version),
target: util::hash_u64(&unit.target),
deps: deps,
local: local,
memoized_hash: Mutex::new(None),
- rustflags: try!(cx.rustflags_args(unit)),
+ rustflags: extra_flags,
});
cx.fingerprints.insert(*unit, fingerprint.clone());
Ok(fingerprint)
let dep_info_loc = fingerprint::dep_info_loc(cx, unit);
let cwd = cx.config.cwd().to_path_buf();
- let rustflags = try!(cx.rustflags_args(unit));
+ rustc.args(&try!(cx.rustflags_args(unit)));
return Ok(Work::new(move |state| {
// Only at runtime have we discovered what the extra -L and -l
}
}
- // Add the arguments from RUSTFLAGS
- rustc.args(&rustflags);
-
state.running(&rustc);
try!(exec_engine.exec(rustc).chain_error(|| {
human(format!("Could not compile `{}`.", name))
.build_out(unit.pkg));
}
+ rustdoc.args(&try!(cx.rustdocflags_args(unit)));
+
let name = unit.pkg.name().to_string();
let build_state = cx.build_state.clone();
let key = (unit.pkg.package_id().clone(), unit.kind);
--- /dev/null
+extern crate cargotest;
+extern crate hamcrest;
+
+use cargotest::support::{project, execs};
+use hamcrest::assert_that;
+
+#[test]
+fn parses_env() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "");
+ p.build();
+
+ assert_that(p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo").arg("-v"),
+ execs().with_status(0)
+ .with_stderr_contains("\
+[RUNNING] `rustdoc [..] --cfg=foo[..]`
+"));
+}
+
+#[test]
+fn parses_config() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "")
+ .file(".cargo/config", r#"
+ [build]
+ rustdocflags = ["--cfg", "foo"]
+ "#);
+ p.build();
+
+ assert_that(p.cargo("doc").arg("-v"),
+ execs().with_status(0)
+ .with_stderr_contains("\
+[RUNNING] `rustdoc [..] --cfg foo[..]`
+"));
+}
+
+#[test]
+fn bad_flags() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "");
+ p.build();
+
+ assert_that(p.cargo("doc").env("RUSTDOCFLAGS", "--bogus"),
+ execs().with_status(101));
+}
+
+#[test]
+fn rerun() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/lib.rs", "");
+ p.build();
+
+ assert_that(p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo"),
+ execs().with_status(0));
+ assert_that(p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=foo"),
+ execs().with_status(0).with_stderr(""));
+ assert_that(p.cargo("doc").env("RUSTDOCFLAGS", "--cfg=bar"),
+ execs().with_status(0).with_stderr("\
+[DOCUMENTING] foo v0.0.1 ([..])
+"));
+}